#include<bits/stdc++.h>
using namespace std;
//#define int long long

const int inf = 0x3f3f3f3f;
int dist[500];
int a[500][500];
bool vis[500];
int n;

int prim()
{
	int ans = 0;
	dist[1] = 0;
	for(int i = 1;i <= n;i++)
	{
		int next = -1;
		for(int j = 1;j <= n;j++)
		{
			if(!vis[j] && (next == -1 || dist[next] > dist[j]))
			{
				next = j;
			}
		}
//		cout<<next<<" "<<ans<<endl;
//		if(next == -1 || dist[next] == inf)
//			return inf;
		ans += dist[next];
		vis[next] = 1;
		for(int j = 1;j <= n;j++)
			dist[j] = min(dist[j], a[next][j]);
	}
	return ans;
}

signed main()
{
	while(cin>>n)
	{
		if(!n)
		{
//			cout<<"Huge input, scanf is recommended.";
			break;
		}
		memset(vis, 0, sizeof vis);
		memset(a, 0x3f, sizeof a);
		memset(dist, 0x3f, sizeof dist);
		int x, y, t;
		for(int i = 1;i <= n*(n-1)/2;i++)
		{
			cin>>x>>y>>t;
			if(a[x][y] != inf)
				a[x][y] = a[y][x] = min(a[x][y], t);
			else
				a[x][y] = a[y][x] = t;
		}
		int ans = prim();
		cout<<ans<<endl;
	}
	cout<<endl;
	system("pause");
	return 0;
}

